package com.chainyoung.component_tmperson.ui.mvp.presenter;

import com.chainyoung.common.appcommon.entity.RecieveAccount;
import com.chainyoung.common.appcommon.entity.Version;
import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.di.scope.ActivityScope;
import com.chainyoung.common.exception.ApiException;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmperson.ui.mvp.contract.AccountInfoContract;
import com.chainyoung.component_tmperson.ui.mvp.contract.HelpCenterContract;

import java.util.TreeMap;

import javax.inject.Inject;

import static com.chainyoung.common.constant.LibConstant.NO_RESULT_ERRORCODE;


@ActivityScope
public class HelpCenterPresenter  extends BasePresenter<HelpCenterContract.Model, HelpCenterContract.View> {

    @Inject
    public HelpCenterPresenter(HelpCenterContract.Model model, HelpCenterContract.View rootView) {
        super(model, rootView);
    }


    public void checkUpdate() {
        addSubscribe(mModel.checkUpdate()
                .compose(RxUtils.<Version>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<Version>(mView) {
                    @Override
                    public void onNext(Version data) {
                        mView.showVersion(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        if (e instanceof ApiException) {
                            if (((ApiException) e).getErrorCode().equals(NO_RESULT_ERRORCODE)) {
                                mView.showVersion(null);
                                return;
                            }
                        }
                        super.onError(e);
                    }
                }));
    }


}
